import promptAction from '@ohos.promptAction'

export default {
    data: {
        form: {
            username: '',
            password : '',
            isRemember : false
        }
    },
    handleUsernameChange(e) {
        this.form.username = e.value
        return this.handleValidate()
    },
    handlePasswordChange(e) {
        this.form.password = e.value
        return this.handleValidate()
    },
    handleCheckChange(e){
        this.form.isRemember = e.checked
    },
    handleValidate() {
        let valid = true
        let {username,password} = this.form
        if(!username){
            this.$element('username').showError({
                error: '用户名不能为空'
            })
            valid = false
        }
        if(!password){
            this.$element('password').showError({
                error: '密码不能为空'
            })
            valid = false
        }
        return valid
    },
    handleLogin() {
        this.handleValidate()

        promptAction.showToast({
            message: JSON.stringify(this.form),
            duration: 2000,
        })
    },
    onInit() {

    }
}